<?php session_start();?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<style type="text/css">	
	h1 {font-family:Arial Verdana 'Tahoma'; font-size:16px; text-align:center; color:#0080C0;}
	span {font-family:'Trebushet MS', Arial; font-size: 8px;}
</style>
<link rel="stylesheet" type="text/css" href="../../css/redmond/jquery-ui-1.10.4.custom.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/ui.jqgrid.css" />
<script src="../../js/jquery-1.10.2.js" type="text/javascript" language="javascript"> </script>
<script src="../../js/jquery-ui-1.10.4.custom.min.js" type="text/javascript" language="javascript"> </script>	
<script src="../../js/i18n/grid.locale-en.js" type="text/javascript" language="javascript"> </script>
<script src="../../js/jquery.jqGrid.min.js" type="text/javascript" language="javascript"> </script>
<script type="text/javascript" language="javascript">		
	$(document).ready(function(){
		<?php
			$report = $_GET['rpt'];
			$year = $_GET['year'];
			$urlsource = '';
			$execute = '';
			$colNames = '';
			$colModel = '';
			$groupField = '';
			switch ($report){
				case 1: 
					$execute = 'fill_grid("#results",\'../../getData.php?opt=annualReports_1&datamember=income&year='.$year.'\');';					
					$execute .= 'fill_grid("#results2",\'../../getData.php?opt=annualReports_1&datamember=expense&year='.$year.'\');';
					$colNames = '\'Enterprise\',\'\', \'\'';
					$colModel = '{name:\'parent_category\',width:150},';
					$groupField = '\'enterpriseName\',\'parent_category\'';
					$groupColumnShow = '[false,false]';
				break;
				case 2: 
					$execute = 'fill_grid("#results",\'../../getData.php?opt=annualReports_2&datamember=expense&year='.$year.'\');';
					$colNames = '\'Enterprise\',\'\',\'\',\'\'';
					$colModel = '{name:\'employeeName\',width:200},{name:\'parent_category\',width:150},';
					$groupField = '\'enterpriseName\',\'employeeName\'';
					$groupColumnShow = '[false,false]';
					$sortName = 'sortname: \'employeeName\'';
				break;
				case 3:
					$execute = 'fill_grid("#results",\'../../getData.php?opt=annualReports_1&datamember=reimbursement&year='.$year.'\');';
					$colNames = '\'Enterprise\',\'\', \'\'';
					$colModel = '{name:\'parent_category\',width:150},';
					$groupField = '\'enterpriseName\',\'parent_category\'';
					$groupColumnShow = '[false,false]';					
				break;
				case 4: 
					$execute = 'fill_grid("#results",\'../../getData.php?opt=annualReports_2&datamember=reimbursement&year='.$year.'\');';
					$colNames = '\'Enterprise\',\'\',\'\',\'\'';
					$colModel = '{name:\'employeeName\',width:200},{name:\'parent_category\',width:150},';
					$groupField = '\'enterpriseName\',\'employeeName\'';
					$groupColumnShow = '[false,false]';
					$sortName = 'sortname: \'employeeName\'';
				break;
			}
		
		?>		
		function fill_grid(object,sUrl){		
			jQuery(object).jqGrid({
			url:sUrl,
			rowNum: 1000,
			datatype: "json",
			height: 'auto',
			colNames:[<?=$colNames?>,'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
			colModel:[
				{name:'enterpriseName'},
				<?=$colModel?>								
				{name:'categoryName',width:175},
				{name:'January',  width:60,formatter:"number", align:"center",summaryType:'sum'}, 
				{name:'February',  width:60,formatter:"number", align:"center",summaryType:'sum'},   						
				{name:'March',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'April',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'May',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'June',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'July',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'August',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'September',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'October',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'November',  width:60,formatter:"number", align:"center",summaryType:'sum'},
				{name:'December',  width:60,formatter:"number", align:"center",summaryType:'sum'}
				
			],   	   	   
			grouping: true,groupingView : {
				groupField : [<?=$groupField?>],
				groupSummary : [true],
				groupColumnShow : <?=$groupColumnShow?>,
				groupCollapse : false,
				groupOrder: ['asc'],
			},caption: $(object).attr('name'), 
			<?=$sortname?>
			loadonce:false
			});
		}
		<?=$execute?>		
	});	
</script>
<span>Generated by: <?=$_SESSION['username']?></span> <br />
<span>Generated on: <?=date('d M y');?></span> <br/ >
	<h1><?=$_GET['reportTitle']?></h1>
	<table id="results" name="results"></table>
	<table id="results2" name="results2"></table>
</body>
</html>